<?php

$t_title = "Редактировать страницу";
$HEADER .=" - ".$t_title;

$t_data = IsPage($GL, $_GET['page']);
if (isset($_GET['page']) and $t_data)
{
    $SCRIPTS .= "
    <script type=text/javascript>
        function afterLoad() {
            var ta = document.getElementsByTagName('textarea')[0];
            ta.value = ta.value.replace(/{EOF}/g, \"\\n\");
        }
        window.onload = window.setTimeout(afterLoad, 500);
    </script>";
    
    if ($_POST["check_yes"] != "yes") {
        $t_tpl = GetTpl("edpage");
        $t_replace = array(
            "{link}" => "http://" . $SITE . "/?action=" . $t_data["link"],
            "{title}" => $t_data["title"],
            "{text}" => htmlspecialchars_decode($t_data["text"], ENT_QUOTES));
        foreach ($t_replace as $k => $v)
            $t_tpl = str_replace($k, $v, $t_tpl);
        $t_BODY = $t_tpl;
    }
    else{
        $t_data = array(
            "title" => stripslashes(trim($_POST["title"])),
            "text"  => str_replace("\n", "{EOF}", htmlspecialchars($_POST["text"], ENT_QUOTES)));

        if (EditPage($GL, $t_data, $_GET['page'])) {
            Logger($LogFile, "ADMIN EDIT PAGE (http://" . $SITE . "/?action=" . $_GET['page'] . ")");
            header("Location: http://" . $SITE . "/?action=" . $_GET['page']);
        }
        else {
            header("Location: http://" . $SITE . "/?action=error");
        }
    }
}
else {
    $t_BODY = "<p>Страница не найдена.</p>";
}

?>
